/**
 * Created by kangmm on 2016/9/26 0026. 定义服务接口路径
 */
// api接口路径
App.apiUrl = {
    //登录页面接口
    // "loginUser":"api/user/login_user",
    "loginUser":"DE5ED2CDD5560E4C86B85D54341ECE92D8CFCFF1DD112C9076A9F48A78E34C71",
    // "getUserCode":"api/user/get_user_code",
    "getUserCode":"DBC2699CCA3DCE4F31B58C8C36F53BE9CCAAAD203D9FB85020770DD087268390",
    // "quitUserURL":"api/user/quit_user_ope",
    "quitUserURL":"BF361B6282160DA466864D31DFFDBB76CEE59BDC35489F75E6A93D9D94F839E9",
    // "modifyPwdURL":"api/user/modify_user_pwd",
    "modifyPwdURL":"67150ED4C315F563384EE9CD83FD13B7DEAAC3CCB2F961BA3934974528CA4AB5",
    //管理用户页面接口
    // "addUser":"api/user/add_user",
    "addUser":"07210ED0E818454E232E4862368AAE60EBAAC5F0EA93FFD438A16AB6DB718EDD",
    // "queryUserAuthURL":"api/user/query_user_auth",
    "queryUserAuthURL":"373F594F4CDC06E7D8A4801D4FF728D317019EDD86456E6DF9DFBFB19C0FCEA5",
    // "queryUserURL":"api/user/query_user",
    "queryUserURL":"373F594F4CDC06E7D8A4801D4FF728D3511CB0E1C6C43F38F432565D9BC41BC8",
    // "deleteUserURL":"api/user/delete_user",
    "deleteUserURL":"A1C2BAD2BDAA44FBBCAC44C02313A6EC9CC7FAC5A978DC34C84C91C1C95C307C",
    // "modifyUserURL":"api/user/modify_user",
    "modifyUserURL":"67150ED4C315F563384EE9CD83FD13B7E07DDD9513A6DE97DE1830F2C1875DBF",
    // "addUserRoleURL":"api/user/add_user_role",
    "addUserRoleURL":"07210ED0E818454E232E4862368AAE602DB63EC2B28A37102E50F723CBD12F1B",
    // "addUserDataAuthURL":"api/user/add_user_data_auth",
    "addUserDataAuthURL":"07210ED0E818454E232E4862368AAE6015B7269B66ABF0656C1380597BE4F000",
    // "getUserBranchURL":"api/user/get_user_branch",
    "getUserBranchURL":"DBC2699CCA3DCE4F31B58C8C36F53BE9E0E9B3AFFCBCB5C8628538944CAD8DAD",
    // "getUserBranchAuthURL":"api/user/get_user_branch_auth",
    "getUserBranchAuthURL":"DBC2699CCA3DCE4F31B58C8C36F53BE92B83FB899C538A8859EC9A6E835A27C1",

    // "getUserDetailURL":"api/user/get_user_detail",
    "getUserDetailURL":"DBC2699CCA3DCE4F31B58C8C36F53BE9856F30C76647240DEC7A4C83C2BA01FC",
    // "queryUserRolesURL":"api/roles/query_user_roles",
    "queryUserRolesURL":"DB3A429040C76F2E2CF32788AB58ADFB7729C64DA78F923DC243F143FEE60B67",
    // "modifyUser":"api/user/modify_user",
    "modifyUser":"67150ED4C315F563384EE9CD83FD13B7E07DDD9513A6DE97DE1830F2C1875DBF",
    // "getEnumInfoURL":"api/user/get_enum_info",
    "getEnumInfoURL":"B9861006D9E28A8EAC38A29AB9CD6B603B4810E2778F2B23C151DB0286148A86",
    // "queryUserTypeURL":"api/user/get_user_type",
    "queryUserTypeURL":"DBC2699CCA3DCE4F31B58C8C36F53BE9E08C1210C268537AE5C15F73DAFC8711",
    //菜单管理页面接口
    // "queryMenuPageURL":"api/menu/query_menu_page",
    "queryMenuPageURL":"DEC1C07266F40E5EFED1B0E5779E7B0B708C643692AA7443DD1A795ABFB2AD8B",
    // "addMenuURL":"api/menu/add_menu",
    "addMenuURL":"0F4AB4FBA15B7074F057A0A2712A3128D8CADB83EB1645ED2C5A7C5680F42994",
    // "queryMenuInfoURL":"api/menu/query_menu_info",
    "queryMenuInfoURL":"DEC1C07266F40E5EFED1B0E5779E7B0BD7D23C08AA7D237DA18E7EFDA65792C4",
    // "updateMenuURL":"api/menu/update_menu",
    "updateMenuURL":"DCA0BADBEF46D1B90F93957E83C440FF956AC7C0C6636492534723EF5EFB2B18",
    // "deleteMenuURL":"api/menu/delete_menu",
    "deleteMenuURL":"E93E07322FC42CCDE09477B14F0C927FCACB872F95F055E380A0DC3EF153795C",
    //角色管理页面接口
    // "deleteRoleURL":"api/roles/delete_role",
    "deleteRoleURL":"D451D6B34F7276C598D4B809034BBE7484657410C366AC49A8A8A00C3A02C613",
    // "queryRolesURL":"api/roles/query_roles_page",
    "queryRolesURL":"DB3A429040C76F2E2CF32788AB58ADFBC905EEA906E5B6B0CC5EDA8F77A9DC0C",
    // "addRolesURL":"api/roles/add_roles",
    "addRolesURL":"090CF2BC4E5D856AE7450064501141464C8ED395E5F63B3849DC66E864644620",
    // "getRolesInfoURL":"api/roles/get_roles_info",
    "getRolesInfoURL":"146456D2BFE4BAC2F062717CE027AAC71400BB55DDE36417BF3E7F644734D784",
    // "modifyRolesURL":"api/roles/modify_roles",
    "modifyRolesURL":"0934E50B8ECBD700CFD5E0277F61426C1A5BB44D52D8AEF9300CD072D9CA692B",
    // "queryRolesMenuURL":"api/roles/query_roles_menu",
    "queryRolesMenuURL":"DB3A429040C76F2E2CF32788AB58ADFB8455114594F4FAAD5D6F06DF50E1727A",
    // "mdfRolesMenuURL":"api/roles/mdf_roles_menu",
    "mdfRolesMenuURL":"58BFFD4BC34CD66DF70113C69C28D207F75A006E73C2A20B9A9A173585E39E70",
    // "queryRolesTypeURL":"api/roles/get_role_type",
    "queryRolesTypeURL":"146456D2BFE4BAC2F062717CE027AAC786DC7A5CE179E444D83CD399B02EC7C4",
    // "queryRolesUserURL":"api/roles/query_roles_user",
    "queryRolesUserURL":"DB3A429040C76F2E2CF32788AB58ADFB05101AF308893DB606164904905DAE0D",
    // "saveRolesUserURL":"api/roles/save_roles_user",
    "saveRolesUserURL":"EDDE53404EE571B85692B4530A9CBF48A24CCE2E8165172856D09CECC1324DA7",
    // "queryAgentCateURL":"api/roles/get_agentCate_type",
    "queryAgentCateURL":"348AA6B59E7C4F1681677634C13E072A94E2A13DC1F6BD04F788C9A0BD4CB207",

    //双录审核页面接口
    // "queryTaskURL":"api/task/query_task",
    "queryTaskURL":"6819CE9FDAFB268FDC2E844B9D388E2BA3BB81D382FD9F952C4F62C464AF574B",
    // "queryTaskNodeApproveURL":"api/task/query_task_node_approve",
    "queryTaskNodeApproveURL":"6819CE9FDAFB268FDC2E844B9D388E2BF284541468C9F11F20BA99D03F49B866C90A84BE24B7B64A6F170369F146E456",
    // "saveNodeApproveURL":"api/task/update_node_approve",
    "saveNodeApproveURL":"199A820A94C57A0541EC2EC5F43D7FB19CE2CEFA410EBE9D7E9A335D3F16526C",
    // "downloadURL":"api/task/file/download",
    "downloadURL":"9A57E464EF4277293AA1E48ED2BDAC5A4B4ACDDAB6084F191B4A0BE7BEFD4DC4",
    //流程基本信息保存
    // "savemanagetask":"api/flowpath/add_flowpath",
    "savemanagetask":"A74E449E837B8C2803F92C8BFAA3DE554728CBADB212E979FBDFD350A90B3B28",
    //流程节点添加
    // "addmanagenode":"api/panelpoint/add_panelpoint",
    "addmanagenode":"967E81D4557A70A3DE643E4B174F33B5A0FA8D27573504101E501826328D7A81",
    //流程节点删除
    // "deletmanagenode":"api/panelpoint/delete_panelpoint",
    "deletmanagenode":"AE06EF16E9DB6C702E2B506D247F5928092703F52A5708796818389449C27092337C3961F1065840FF7C0E81F912B4A0",
    //流程节点修改
    // "updatemanagenode":"api/panelpoint/update_panelpoint",
    "updatemanagenode":"A4E71FD0DF33B55DB467E5ED7A1385E4E2D3499DC97986D70700417E5C0BD3EA539FAE95B95F6FD17CA8C785E615DD59",
    // "checkmanage":"api/panelpoint/query_panelpoint",
    "checkmanage":"6151D753A67BD9C4F92F6E055C0A2B7C9842846CA5D8872635D78C62298FCAF3",
    //查看流程节点
    // "checkmanagenode":"api/panelpoint/query_panelpointById",
    "checkmanagenode":"6151D753A67BD9C4F92F6E055C0A2B7C8066D09B01404EF841FE557C285B21D83E1D53143357635B5B9802F9FC7973C1",
    //流程信息查询初始化方法
    // "checkmanagecheck":"api/flowpath/query_list",
    "checkmanagecheck":"7E71A0938E43E83AEBD7B72EC8DEA1DDA575FBDFE98241B8BABDA30D0CEF1FDF",
    // "initmanagetask":"api/flowpath/to_flowpath",
    "initmanagetask":"85A9E3185590B4F8EDB213224FA2D3836604D0438A6CAD71377574AC4A04A822",
    //返回流程基本信息
    // "returnmanagetask":"api/flowpath/search_FlowPath",
    "returnmanagetask":"53FE112BCFBF0E1EB4E598F49CF7B6FF04BCC824A82B9C405B671063A1EFF78B",
    //流程基本信息修改
    // "updatemanagetask":"api/flowpath/update_FlowPath",
    "updatemanagetask":"267AB853E28B412C3E0F1A1CB8F7AE7BFCB053193995538B898FD99F235E21C2",
    //流程加点查询页面删除
    // "deletmanage":"api/flowpath/delete_FlowPath",
    "deletmanage":"9A96A562BEA1D12EBAB94670F96AB0F0728487068383195202CDDAC22C515305",
    //伙伴新增
    // "addfriend":"api/friend/add_friend",
    "addfriend":"2C82CEC24B3AFF1C1C9D49CBA7965213EFF788A900C2B475064EA91B91497941",
    //伙伴查询
    // "checkfriend":"api/friend/page_friend",
    "checkfriend":"0C03E06D033AEADC6D020552D28BE4E6E6E027B319F92A1D1BFB558E24025952",
    //伙伴修改初始化
    // "modfriend":"api/friend/query_friends",
    "modfriend":"F9F44C1DB950ABED9EEAE5B0A6DADE8AD0CEB9A1940EE6A5F13083F4542E95FC",
    //伙伴修改方法
    // "updatefriend":"api/friend/update_friends",
    "updatefriend":"0265CCD667B27275C7FE7B5CC93EA991CCAFEDEA7AE88274FB67A3557EED3518",
    //伙伴删除
    // "deletfriend":"api/friend/delete_friends"
    "deletfriend":"1AD92AE3C2CDA1896E060DC64AD9B823C021F7C20EAC0D51C57A4BD4D42048F6"
};
App.getApiUrl = function(apiName) {
	for(var i in App.apiUrl) {
		if (App.apiUrl[i].includes("/")) {
			console.log(1)
			break
		} else {
            App.apiUrl[i] = Decrypt(App.apiUrl[i])
            // console.log(App.apiUrl[i]);
		}
	}
	console.log(App.apiUrl);
	var baseUrl = App.envUrl.baseUrl;
	if(baseUrl == undefined || baseUrl == "") {
		var baseUrl = "http://" + window.location.host + "/";
		if(window.location.href.split("/").length >= 4) {
			baseUrl += window.location.href.split("/")[3] + "/";
		}
	}
	return baseUrl + App.apiUrl[apiName];
}

App.getBaseUrl = function() {
	var baseUrl = App.envUrl.baseUrl;
	if(baseUrl == undefined || baseUrl == "") {
		var baseUrl = "http://" + window.location.host + "/";
		if(window.location.href.split("/").length >= 4) {
			baseUrl += window.location.href.split("/")[3] + "/";
		}
	}
	return baseUrl;
}

App.exApiUrl = {

};

App.getExApiUrl = function(exUrl, apiName) {
	return App.envUrl[exUrl] + App.exApiUrl[apiName];
}

/**
 * 获取URL参数
 *
 * @return {String} name
 */
App.getmtParam = function(name) {
	var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
	var r = window.location.search.substr(1).match(reg);
	if(r) {
		return decodeURI(r[2]);
	}
	return null;
}

/**
 * 获取URL参数
 *
 * @return {String} name
 */
App.getParam = function(name) {
	var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
	var r = window.location.search.substr(1).match(reg);
	if(r) {
		return decodeURI(r[2]).replace(/</g, "&lt;").replace(/>/g, "&gt;");
	}
	return null;
}

/**
 * 获取编码后的参数字符串
 *
 * @param {string}
 *            url 传入的URL
 * @param {sting}
 *            encodeParam 指定的需要编码的参数
 */
App.encodeParams = function(url, encodeParam) {
	var pairs = [],
		map = [],
		str = '',
		value;
	pairs = url.split('&');
	for(var i = 0, len = pairs.length; i < len; i++) {
		value = (pairs[i].charAt(0) == '?') ? pairs[i].replace(/\?/, "") :
			pairs[i];
		// map = pairs[i].split('=');
		// 获得参数键值对
		map[0] = value.substr(0, value.indexOf("="));
		map[1] = value.substr(value.indexOf("=") + 1, value.length);
		// 对指指定参数进行编码
		$.each(encodeParam, function(i, param) {
			if(map[0] == param) {
				map[1] = encodeURIComponent(map[1]);
			}

		});
		// 拼接参数串
		if(map[0] && i < len - 1) {
			str += (map[0] + "=" + map[1] + "&");
		} else {
			str += (map[0] + "=" + map[1]);
		}
	}

	return "?" + str;

};

/**
 * 判断当前是否在微信内置浏览器
 */
App.isWeiXin = function() {
	var ua = window.navigator.userAgent.toLowerCase();
	if(ua.match(/MicroMessenger/i) == 'micromessenger') {
		return true;
	} else {
		return false;
	}
};
//测试
if(App.env == "Test") {
	$("title").append("");
}

/**
 * 判断当前是否在微信内置浏览器
 */
App.ajax = function(request) {
	$.ajax({
        type: request.type,
        url: request.url,
        async: true,
        dataType: "json",
        data:request.data ? request.data : {},
        success: function (data) {
            if(request.success){
            	request.success(data);
            }
        },
        error:function(data){
        	try {
				if(JSON.parse(data.responseText).ret == "30000"){
					parent.showAlert(JSON.parse(data.responseText).msg,function(){
						parent.window.location.href = App.getBaseUrl() + "login.html";
					});
				} else {
					parent.showAlert(JSON.parse(data.responseText).msg,function(){
						if(request.error){
							request.error();
						}
					});
				}
			} catch (err) {
				parent.showAlert("请求失败 ");
			}
        }
    });
};